package com.kh.samr.service.impl;

import com.kh.samr.dto.DishonestyListOldDto;
import com.kh.samr.entity.Dishonesty;
import com.kh.samr.repository.IDishonestyRepository;
import com.kh.samr.service.IDishonestyService;
import com.kh.samr.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Harry
 * @date 2020/12/14
 */
@SuppressWarnings("DuplicatedCode")
@Service
@Transactional
public class DishonestyServiceImpl implements IDishonestyService {
	
	private static final Logger log = LoggerFactory.getLogger(DishonestyServiceImpl.class);
	
	@Resource
	IDishonestyRepository dishonestyRepository;
	
	@Override
	public ResultUtil<List<DishonestyListOldDto>> findAll() {
		log.info("方法名称：findAll;参数：" + null);
		List<Dishonesty> dishonestyList = this.dishonestyRepository.findAll();
		List<DishonestyListOldDto> dishonestyListDtoListOld = new ArrayList<>();
		for (Dishonesty dishonesty : dishonestyList) {
			DishonestyListOldDto dishonestyListOldDto = new DishonestyListOldDto();
			BeanUtils.copyProperties(dishonesty, dishonestyListOldDto);
			dishonestyListDtoListOld.add(dishonestyListOldDto);
		}
		ResultUtil<List<DishonestyListOldDto>> result = new ResultUtil<>(dishonestyListDtoListOld);
		log.info("方法名称：findAll;返回值：" + result);
		return new ResultUtil<>(dishonestyListDtoListOld);
	}
	
	@Override
	public ResultUtil<List<DishonestyListOldDto>> findAllByUniformSocialCreditCode(String uniformSocialCreditCode) {
		log.info("方法名称：" + "findAllByUniformSocialCreditCode" +
				";参数：uniformSocialCreditCode:" + uniformSocialCreditCode);
		List<Dishonesty> dishonestyList = this.dishonestyRepository
				.findAllByUniformSocialCreditCode(uniformSocialCreditCode);
		List<DishonestyListOldDto> dishonestyListDtoListOld = new ArrayList<>();
		for (Dishonesty dishonesty : dishonestyList) {
			DishonestyListOldDto dishonestyListOldDto = new DishonestyListOldDto();
			BeanUtils.copyProperties(dishonesty, dishonestyListOldDto);
			dishonestyListDtoListOld.add(dishonestyListOldDto);
		}
		ResultUtil<List<DishonestyListOldDto>> result = new ResultUtil<>(dishonestyListDtoListOld);
		log.info("方法名称：" + "findAllByUniformSocialCreditCode" + ";返回值：" + result);
		return new ResultUtil<>(dishonestyListDtoListOld);
	}
}
